<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class AppController extends Controller {

    var $name = "App";
    public $components = array(
        'Session',
        'Auth' => array(
            'authorize' => array(
                'Actions' => array('actionPath' => 'controllers')
            )
        ),
        'RequestHandler',
        'Acl'
    );
    var $helpers = array('Html', 'Form', 'Javascript', "Ajax", 'Session', 'Js');

    function beforeFilter() {
        //Disable error reporting
        //COMENTAR Y DESCOMENTAR ESTA LIENA ES LA QUE MUESTRA ERRORES O NO EN CAKE
         error_reporting(0);
        //Report runtime errors
         $this->Auth->allow(array('login', 'send', 'logout', 'display'));
        //$this->Auth->allow(array('*'));
        $this->disableCache();

        //Se realiza cuando la petición no es ajax. Cuando carga toda la página.
        //$this->set('usuario', $this->Auth->user('nombre') . " " . $this->Auth->user('primer_apellido') . " " . $this->Auth->user('segundo_apellido'));
       $this->Auth->autoRedirect = false; 
        if (isset($this->params['admin'])) {
            $this->Auth->authError = 'Está tratando de entrar a una zona  restringida ';
            $this->Auth->loginAction = array('controller' => 'users', 'action' => 'admin_login');
            $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'admin_home');
          //  $this->Auth->logoutRedirect = array('controller' => 'display', 'action' => 'home');
            
        } else {

            $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
            $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
            $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
            $this->Auth->authError = 'Está tratando de entrar a una zona  restringida';
        }


        //$this->Session->write('Auth.redirect', null);
    }

}

?>
